//
// Created by 郑开心 on 15/12/11.
// Copyright (c) 2015 郑开心. All rights reserved.
//

import Foundation
import Alamofire
import SwiftyJSON

class UserTool: NSObject {

    class func unreadWithUid(success:(result: UserResult) -> Void,failure:(error:NSError?) -> Void){
        var param = [String:String]()
        param["access_token"] = AccountTool.readAccount()?.access_token
        param["uid"] = AccountTool.readAccount()?.uid
        Alamofire.request(.GET,"https://rm.api.weibo.com/2/remind/unread_count.json",parameters: param).responseJSON { response in
            if let value = response.result.value {

                let data = JSON(value)
                let result = UserResult(json: data)
                success(result: result)
            }else {
                failure(error: response.result.error)
            }
        }
    }
    
    class func userInfo(success:(result: User) -> Void,failure:(error:NSError?) -> Void){
        var param = [String:String]()
        param["access_token"] = AccountTool.readAccount()?.access_token
        param["uid"] = AccountTool.readAccount()?.uid
        
        Alamofire.request(.GET,"https://api.weibo.com/2/users/show.json",parameters: param).responseJSON { response in
            if let value = response.result.value {
                
                let data = JSON(value)
                let result = User(json: data)
                success(result: result)
            }else {
                failure(error: response.result.error)
            }
        }
    }

}
